package Yki.PaperPlaneClient.Adapter;

import java.util.List;
import java.util.Map;

import Yki.PaperPlaneClient.R;
import Yki.PaperPlaneClient.XML.XMLUtils;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LetterContentAdapter extends BaseAdapter {
	private List<Map<String, Object>> mPlanes;
	private Context mContext;
	public LetterContentAdapter(Context context,List<Map<String, Object>> planes) {
		// TODO Auto-generated constructor stub
		mPlanes = planes;
		mContext = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		//return mPlanes.size();
		if (mPlanes == null ) {
			return 0;
		}
		else {
			return mPlanes.size();
		}
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = LayoutInflater.from(mContext).inflate(R.layout.letter_content_item, null);
		
		ImageView head = (ImageView) view.findViewById(R.id.content_head);
		head.setImageBitmap((Bitmap) mPlanes.get(position).get("image"));
		
		TextView sender = (TextView) view.findViewById(R.id.list_content_name);
		sender.setText(mPlanes.get(position).get(XMLUtils.TAG_SENDER_NAME).toString());
		
		TextView date = (TextView) view.findViewById(R.id.list_content_date);
		date.setText(mPlanes.get(position).get(XMLUtils.TAG_DATE).toString());
		
		TextView message = (TextView) view.findViewById(R.id.content_message);
		message.setText(mPlanes.get(position).get(XMLUtils.TAG_MESSAGE).toString());
		
		return view;
	}
	
}